home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11936 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: pop.gnn.com!HoangTQ
  2. From: Tuyen Hoang <HoangTQ@gnn.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need Help With CSC Homework
  5. Date: Sat, 16 Mar 1996 22:33:58
  6. Organization: GNN
  7. Message-ID: <4ig16m$h3p@news-e2c.gnn.com>
  8. References: <4g0qq4$o0@news.nevada.edu>
  9. NNTP-Posting-Host: www-29-26.gnn.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset="us-ascii"
  12. X-GNN-NewsServer-Posting-Date: 17 Mar 1996 03:33:42 GMT
  13. X-Mailer: GNNmessenger 1.2
  14.  
  15.  
  16. In article <4g0qq4$o0@news.nevada.edu> Troy Kessler 
  17. wrote:
  18.  
  19. >I am a computer student at UNLV. My assignment is to create a roman 
  20. >calculator with a roman class. My professor wants me to overload 
  21. > >>,<<,+,-,/, and *. I am having a problem. I am using Borland Turbo C++ 
  22. >for DOS. It says expected ) on line 88 of pfun.cpp. This is the 
  23. >DecimalToRoman function. (the first line) I will post the list of 
  24. >pmain.cpp pfun.cpp p.h. Please help me with my error. E-mail prefered.
  25. >
  26. >    Thank You Very Much
  27. >Troy 3.14159265358979323846264338327950288..... 
  28. Kessler
  29.  
  30.  
  31. Did you only have one error message?
  32. I recompile your code-without modification- with Borland Turbo C v. 1.01 and 
  33. get five(5) error, all of them complain about an undefined object name 
  34. 'answerr' in the function DecimalToRoman(), and a warning in main() that says 
  35. the variable answerr is never used. Do you got some things like mine?
  36. You might want to look at my comment in the file pfun.c
  37.  
  38. There are serious problems in your algorithm, too.  
  39. You use an char array[21] for store the Roman number, so the greatest number 
  40. is 20,000(20 letters M). How about the next one? 19,999? No, it's 19,500(19 
  41. letters M and 1 for D)those numbers from 19,501 to 19,999 are *out* of 
  42. your hand. There are more, 19,100(19 letters M and 1 for C) is ok, but those 
  43. numbers from 19,101 to 19,499 are all gone. I don't have the patient to 
  44. count all of them, but at least, I do know the problem begins at 9,888(MMM MMM 
  45. MMM DCCC LXXX VIII : 21 letters). Surprise?
  46.  
  47. The second problem is that there are NO Roman number IIII or VIIII as you try 
  48. to implement, all I know is that number four is IV and number 9 is IX, etc.
  49. Suppose that your implement is acceptable, so you jump in to trouble at 
  50. 6,999(MMM MMM DCCCC LXXXX VIIII : 21 letter) much earlier than the ancient 
  51. Romans did.
  52.  
  53. Increase the value of MAXLENGTH won't solve this problem, the correct solution 
  54. is using dynamic allocation: allocate the char* after calculate it length at 
  55. run time instead of using static char[MAX].
  56.  
  57. If you want a hasty solution, I have it handy: the value range for type 
  58. unsigned int is from 0 to 65,xxx(for PC), therefore for your Roman number's 
  59. safety, you should set MAXLENGTH to 65+15+1 = 81. If you want to use long 
  60. instead, you should increase MAXLENGTH accordingly.
  61.  
  62. I don't know if you have time to make it up again.
  63.  
  64. So good luck.
  65.  
  66. Hoang Tuyen Q.
  67. HoangTQ@gnn.com
  68.  
  69.